# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_library(
    name = "sequencing",
    srcs = [
        "sequencing.cc",
    ],
    hdrs = [
        "sequencing.h",
    ],
    deps = [
        ":ir_cc_proto",
        "//gutil:collections",
        "//gutil:status",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/functional:function_ref",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:optional",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "pd",
    srcs = [
        "pd.cc",
    ],
    hdrs = [
        "pd.h",
    ],
    deps = [
        ":ir",
        ":ir_cc_proto",
        "//gutil:collections",
        "//gutil:proto",
        "//gutil:status",
        "//p4_pdpi/internal:ordered_map",
        "//p4_pdpi/utils:ir",
        "@com_github_google_glog//:glog",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@com_google_googleapis//google/rpc:code_cc_proto",
        "@com_google_googleapis//google/rpc:status_cc_proto",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_binary(
    name = "pdgen",
    srcs = ["pdgen.cc"],
    deps = [
        ":ir",
        ":ir_cc_proto",
        ":pdgenlib",
        "//gutil:proto",
        "//gutil:status",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/flags:usage",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "pdgenlib",
    srcs = [
        "pdgenlib.cc",
    ],
    hdrs = [
        "pdgenlib.h",
    ],
    deps = [
        ":ir_cc_proto",
        ":pd",
        "//gutil:collections",
        "//gutil:status",
        "//p4_pdpi/internal:ordered_map",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "p4info_union_lib",
    srcs = ["p4info_union_lib.cc"],
    hdrs = [
        "p4info_union_lib.h",
    ],
    deps = [
        "//gutil:proto",
        "//gutil:status",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4types_cc_proto",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:optional",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_binary(
    name = "p4info_union",
    srcs = ["p4info_union.cc"],
    deps = [
        ":p4info_union_lib",
        "//gutil:proto",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/flags:usage",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "ir",
    srcs = [
        "ir.cc",
    ],
    hdrs = [
        "ir.h",
    ],
    deps = [
        ":ir_cc_proto",
        "//gutil:collections",
        "//gutil:proto",
        "//gutil:status",
        "//p4_pdpi/utils:ir",
        "@com_github_google_glog//:glog",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_github_p4lang_p4runtime//:p4types_cc_proto",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googleapis//google/rpc:code_cc_proto",
        "@com_google_googleapis//google/rpc:status_cc_proto",
        "@com_google_protobuf//:protobuf",
    ],
)

proto_library(
    name = "ir_proto",
    srcs = ["ir.proto"],
    deps = [
        "@com_github_p4lang_p4runtime//:p4info_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_proto",
        "@com_google_googleapis//google/rpc:code_proto",
        "@com_google_googleapis//google/rpc:status_proto",
    ],
)

cc_proto_library(
    name = "ir_cc_proto",
    deps = [":ir_proto"],
)

cc_library(
    name = "p4_runtime_session",
    srcs = [
        "p4_runtime_session.cc",
    ],
    hdrs = [
        "p4_runtime_session.h",
    ],
    deps = [
        ":ir",
        ":ir_cc_proto",
        ":sequencing",
        "//gutil:status",
        "//p4_pdpi/utils:ir",
        "//sai_p4/fixed:p4_roles",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/numeric:int128",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "pi",
    srcs = ["pi.cc"],
    hdrs = ["pi.h"],
    deps = [
        ":ir_cc_proto",
        "//gutil:collections",
        "//gutil:status",
        "//p4_pdpi/utils:ir",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "ir_tools",
    srcs = ["ir_tools.cc"],
    hdrs = ["ir_tools.h"],
    deps = [
        ":ir_cc_proto",
        "//gutil:collections",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4types_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_test(
    name = "ir_tools_test",
    srcs = ["ir_tools_test.cc"],
    deps = [
        ":ir_cc_proto",
        ":ir_tools",
        ":pd",
        "//gutil:proto",
        "//gutil:proto_matchers",
        "//gutil:status_matchers",
        "//gutil:testing",
        "//p4_pdpi/testing:main_p4_pd_cc_proto",
        "//p4_pdpi/testing:test_p4info_cc",
        "@com_github_p4lang_p4runtime//:p4types_cc_proto",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)
